import json
import os
import sys

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd + "../")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hf_mall.settings")

import django

django.setup()
from goods.models import Goods, GoodsImage

with open('./json/4/images.json', 'r', encoding='utf8')as fp:
    row_data = json.load(fp)

for image in row_data:
    image_instance = GoodsImage()
    image_instance.image_id = image['image_id']
    image_instance.image_path = image['image_url']
    image_instance.good = Goods.objects.filter(good_sn=image['good_sn'])[0]
    image_instance.save()